let submitNum = 0;
let productid, tempname;
let MealList = []
layui.config({
    version: "1510164124181",
}).use(
    ["form", "laydate", "laypage", "layer", "element", "upload", "jquery"],
    function () {
        form = layui.form;
        layer = layui.layer;
        laydate = layui.laydate; //日期
        laypage = layui.laypage; //分页
        element = layui.element; //元素操作
        upload = layui.upload; //上传

        TypelistByTypeId(2);
        productid = GetQueryString("productid");
        tempname = GetQueryString("tempname");

        if (
            productid == undefined ||
            productid == null ||
            productid == "" ||
            productid == "undefined" ||
            productid == 0
        ) {
            productid = 0;
        } else {
            ProductlistById();
        }
        //layui普通图片上传
        let uploadInst = upload.render({
            elem: "#uploadimgs",
            url:
                httpurl + "/uploadImgQiniu?pathName=productImg&&divisor=1&dividend=1",
            // ,size: 150
            before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $("#divpreview").css("display", "block");
                    $("#preview").attr("src", result); //图片链接（base64）
                });
            },
            done: function (res) {
                // console.log(JSON.stringify(res)+"=======done");
                if (res.rtnCode == 500) {
                    //如果上传失败

                    $("#divpreview").css("display", "none");
                    $("#preview").attr("src", ""); //图片链接（base64）
                    return layer.msg(res.msg);
                }
                $("#preview").attr("name", res.msg); //图片链接（base64）
            },
            error: function () {
                //演示失败状态，并实现重传
                var demoText = $("#demoText");
                demoText.html(
                    '<span style="color: #FF5722;">上传失败</span> <a class="layui-btn  demo-reload">重试</a>'
                );
                demoText.find(".demo-reload").on("click", function () {
                    uploadInst.upload();
                });
            },
        });

        //累加图片
        $("#addqujian").click(function () {
            $("#addqujian").before(
                '<div class="form-group-col-2 lunt goods_list">' +
                "<div>" +
                '<input type="file" name="file"  onchange="upload_img(this,\'productImg\');" style="display: none;" />' +
                '<input class="btn btn-warning" value="请上传图片"  onclick="addclick(this)" type="button"/>' +
                //'<input class="btn btn-warning" value="请上传图片" onclick="upload_img(this)" type="button" id="uploadimgs_'+ii+'"/>'+
                '<span class="word-aux">请上传的图片宽高比例为1:1</span>' +
                "</div>" +
                "</div>" +
                '<div class="form-group-col-2 luntu" class="divpreview" id="divpreview_' +
                ii +
                '" style="display:none">' +
                "<div>" +
                '<img id="preview_' +
                ii +
                '" class="preview" src="#" height="100" />' +
                '<p id="demoText_' +
                ii +
                '" class="demoText"></p>' +
                "</div>" +
                "</div>"
            );
            ii++;
        });

        $("#removequjian").click(function () {
            var lens = $(".lunt").length;
            if (lens == 0) {
                layer.alert("至少保留一个商品轮播图片");
            } else {
                $(".lunt").last().remove();
                $(".luntu").last().remove();
            }
        });

        $(".img_serch").click(function () {
            $(".mask").show();
            $(".dialog").show();
        });
        $(".add_rules").click(function () {
            $(".tableBorder_content").append(`<tr class="rules">
        <td></td>
        <td><input class="mealname" style="width:100%" placeholder="请输入套餐名"/></td>
        <td><input type='number' class="mealprice" min="0" onkeyup="onlyNumber(this)" style="width:100%" value="0" placeholder="请输入现价"/></td>
        <td><input type='number' class="discount" min="0" style="width:100%" value="9" placeholder="请输入折扣"/></td>
        <td><input type='number' class="mealoldprice" min="0" onkeyup="onlyNumber(this)" style="width:100%" value="0" placeholder="请输入市场价"/></td>
        <td><input type='number' class="mealstock" min="0" value="300" onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^0-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" style="width:100%" placeholder="请输入库存"/></td>
        <td><input type='number' class="freight" min="0" style="width:100%" value="0" placeholder="请输入邮费"/></td>
        <td><input type='number' class="newspecials" min="0" style="width:100%" onkeyup="onlyNumber(this)" value="0" placeholder="请输入新人专享价"/></td>
        <td class="proMarks"><button onclick="addProductDelivery(this,'button');return false;" class='customization-button' style='width: 80px;
    font-size: 14px;
    height: 30px;'>添加</button></td>
        <td><span onclick="deleteRule(this)">删除</span></td>
      </tr>`);
        });
    }
);

//查询商品
function ProductlistById() {
    $.ajax({
        url: httpurl + "/ProductlistByIdPc",
        cache: false,
        headers: {
            "Access-Control-Allow-Origin": "*",
            "Access-Control-Allow-Methods": "*",
            "Access-Control-Allow-Headers": "Authorization",
            Authorization: GetTokenInfo(),
        },
        contentType: "application/json",
        data: {
            type: 0,
            id: productid,
        },
        // dataType: "json",
        success: function (data) {
            // console.log("ProductlistById======"+JSON.stringify(data));
            if (data.rtnCode == 200) {
                let dataList = data.data.ProductList;
                MealList = data.data.MealList;
                $(
                    "#types option[value=" +
                    (dataList.typeEntity == null ? 0 : dataList.typeEntity.id) +
                    "]"
                ).attr("selected", "selected");
                $("#pro_name").val(dataList.title);
                $("#identify").val(dataList.identify);

                $(
                    'input:radio[name="isshelves"][value="' + dataList.isshelves + '"]'
                ).attr("checked", "true");
                $("#sort").val(dataList.sort);

                if (
                    dataList.headimg != null &&
                    dataList.headimg != "" &&
                    dataList.headimg != undefined
                ) {
                    $("#preview").attr("src", visitimgurl + "/" + dataList.headimg);
                    $("#preview").attr("name", dataList.headimg);
                    $("#divpreview").show();
                }
                $("#bname").val(dataList.bname);
                $('input:radio[name="give"][value="' + dataList.give + '"]').attr(
                    "checked",
                    "true"
                );
                $('input:radio[name="isfree"][value="' + dataList.isfree + '"]').attr(
                    "checked",
                    "true"
                );
                $('input:radio[name="isnew"][value="' + dataList.isnew + '"]').attr(
                    "checked",
                    "true"
                );
                $('input:radio[name="iscrux"][value="' + dataList.iscrux + '"]').attr(
                    "checked",
                    "true"
                );
                $(
                    'input:radio[name="isrecomm"][value="' + dataList.isrecomm + '"]'
                ).attr("checked", "true");
                $(
                    'input:radio[name="exchanges"][value="' + dataList.exchanges + '"]'
                ).attr("checked", "true");
                $(
                    'input:radio[name="isrecommtu"][value="' + dataList.isrecommtu + '"]'
                ).attr("checked", "true");

                UE.getEditor("container").setContent(dataList.details)
                select_img_list(dataList.img);
                select_meal_list();
                if (
                    !(
                        tempname == undefined ||
                        tempname == null ||
                        tempname == "" ||
                        tempname == "undefined" ||
                        tempname == 0
                    )
                ) {
                    $("input").attr("readonly", true);

                    $("textarea").attr("readonly", true);

                    $(":radio").attr("disabled", true);
                    $(":checkbox").attr("disabled", true);
                    $(":button").attr("disabled", true);
                    $("a").removeAttr("onclick");
                    $("select").attr("disabled", true);
                    var ue = UE.getEditor("container");
                    $(".rules i").parent().remove();
                    $(".returns").remove("readonly");
                    ue.ready(function () {
                        //不可编辑
                        ue.setDisabled();
                    });
                }
            } else {
                top.layer.msg(data.msg);
            }
        },
    });
}

var tempEvent = {};

// 添加发货商品
let addProductDelivery = debounce(function (e, el) {
    tempEvent.event = e;
    handleSearchProMarkList(el);
}, 500);
function pageInfo() {
    laypage.render({
        elem: "pageInfo", //注意，这里的 test1 是 ID，不用加 # 号
        count: totalRecords, //数据总数，从服务端得到
        curr: pageNo,
        layout: ["prev", "page", "next", "limit"],
        limit: pageRecords,
        jump: function (obj, first) {
            //首次不执行
            if (!first) {
                //obj包含了当前分页的所有参数，比如：
                pageNo = obj.curr;
                pageRecords = obj.limit;
                queryPD()
            }
        },
    });
}
function dataToDom(data) {
    let str;
    str = `<div class='addPd'><form class='pdForm'>
            <div><span>商品编号：</span><input type="number" placeholder='请输入商品编号' class="brand-number"/></div>
            <div><span>产品名称：</span><input placeholder='请输入产品名称' class="pro-name"/></div>
            <button class='customization-button' style='width: 60px;
    font-size: 14px;
    height: 25px;' onclick='handleSearchProMarkList2();return false;'>查询</button>
        </form><table border='1' cellspacing="0" cellpadding="10" class='pdTable'><thead>
        <tr>
        <th></th>
        <th>商品编号</th>
        <th>产品名字</th>
        </tr>
        </thead><tbody>`;
    data.data.list.forEach((res) => {
        str += `
          <tr>
            <td>
            <div class="form-cont" class="exchanges">
                <label class="radio">
                    <input type="radio" value='${JSON.stringify(
            res
        )}' name="exchanges" /><span></span>
                </label>
            </div></td>
            <td>${res.number}</td>
            <td>${res.name}</td>
          </tr>
          `;
    });
    str += `</tbody></table>
        <div id='pageInfo'></div>
        <div class='confim'>
             <button class='customization-button' style='width: 70px;
    font-size: 14px;
    height: 35px;' onclick='hidePopup(this);return false;'>确定</button>
        </div>
      </div>`;

    return str;
}
function handleSearchProMarkList2() {
    queryPD().then(res => {
        pageInfo()
    })
}
function handleSearchProMarkList(el) {
    pageNo = 1
    queryPD(1).then(res => {
        layer.open({
            title: "添加发货产品",
            type: 1,
            area: ["700px", "600px"],
            shadeClose: false, //点击遮罩关闭
            content: dataToDom(res),
            success: () => {
                pageInfo()
            },
            end: () => {
                $("body").css({ overflow: "" });
                if (tempEvent.value) {
                    $(tempEvent.event).parents('.proMarks').append(`
            <div style='display:flex;margin:5px 0px;' class="proMark-box">
            <textarea data-id='data' style='width:120px;' placeholder='请输入产品名称'>${tempEvent.value.name}</textarea>
            <div style='display: flex;
            flex-direction: column;justify-content: center;padding:0 5px'><div><span>数量:</span><input type='number' value='1' placeholder='请输入数量' style="width:30px"/></div></div>
            <div style='display: flex;
            flex-direction: column;'><i class="layui-icon" style='color:#ff4444;font-size:20px;cursor: pointer;' onclick='delDp(this)'>&#xe640;</i><i class="layui-icon" style='color:#ff4444;font-size:20px;cursor: pointer;' onclick='addProductDelivery(this)'>&#xe61f;</i>
            </div>
            `);
                    if (el == 'button') {
                        $(tempEvent.event).css({ display: "none" });
                    }
                    tempEvent.value = null;
                    tempEvent.event = null;
                }
            },
        });
    })

}
function hidePopup(e) {
    let temp = $(".addPd").find(":radio:checked").val();
    if (temp) {
        let data = JSON.parse(temp);
        console.log(data);
        tempEvent.value = data;
        layer.closeAll();
    } else {
        layer.open({
            title: "提示",
            content: "请选择一个产品",
        });
    }
}
// 删除标签
function delDp(e) {
    let parent = $(e).parents("td");
    let length = $(e).parents("td").find(".proMark-box").size();
    console.log(length);
    if (length == 1) {
        console.log(parent.find("button"));
        parent.find("button").css({ display: "inline-block" });
    }
    $(e).parent("div").parent("div").remove();
}

function queryPD(num) {
    let number = $('.brand-number').val()
    let proname = $('.pro-name').val()
    return new Promise((resolve, rejects) => {
        $.ajax({
            type: "GET",
            url: httpurl + "/selectProduceList",
            cache: false,
            // async: false,
            headers: {
                "Access-Control-Allow-Origin": "*",
                "Access-Control-Allow-Methods": "*",
                "Access-Control-Allow-Headers": "Authorization",
                Authorization: GetTokenInfo(),
            },
            contentType: "application/json",
            data: {
                "pageNo": pageNo,
                "pageSize": pageRecords,
                "number": number,
                "name": proname
            },
            success: (res) => {
                console.log(res);
                if (res.rtnCode == 200) {
                    resolve(res)
                    totalRecords = res.data.total
                    if (num == undefined) {
                        let str = ''
                        res.data.list.forEach((item) => {
                            str += `
                          <tr>
                            <td>
                            <div class="form-cont" class="exchanges">
                                <label class="radio">
                                    <input type="radio" value='${JSON.stringify(item)}' name="exchanges" /><span></span>
                                </label>
                            </div></td>
                            <td>${item.number}</td>
                            <td>${item.name}</td>
                          </tr>
                          `;
                        })

                        $('.pdTable tbody').html(str)
                    }
                } else {
                    top.layer.msg("暂无数据，请前往<物流管理-产品更新表>添加产品");
                }



            },
        });
    })

}

function select_meal_list() {
    let rule = [];
    for (let i = 0; i < MealList.length; i++) {
        let temp = MealList[i];
        let module = ''
        module = `
    <tr class="rules" id="${temp.id}">
      <td>${temp.id}</td>
      <td><input value="${temp.meal || ""}" placeholder="请输入套餐名" class="mealname"/></td>
      <td><input type='number' value="${temp.newprice
            }" placeholder="请输入现价" class="mealprice" min="0"  onkeyup="onlyNumber(this)" style="width:100%"/></td>
      <td><input type='number' value="${temp.discount
            }" placeholder="请输入折扣" class="discount" min="0" style="width:100%"/></td>
      <td><input type='number' value="${temp.oldprice
            }" placeholder="请输入市场价" class="mealoldprice" min="0" onkeyup="onlyNumber(this)" style="width:100%"/></td>
      <td><input type='number' value="${temp.stock
            }" placeholder="请输入库存" class="mealstock" min="0" onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^0-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" style="width:100%"/></td>
      <td><input type='number' value="${temp.freight
            }" placeholder="请输入邮费" class="freight" min="0" onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^0-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" style="width:100%"/></td>
      <td><input type='number' value="${temp.newspecials
            }" placeholder="请输入新人专享价" class="newspecials" min="0" onkeyup="onlyNumber(this)" style="width:100%"/></td>
      `
        if (temp.produceList) {
            let produceList = JSON.parse(temp.produceList)
            // [{"produceName": '024麦包包',"amount": 2},{"produceName": '025薯片',"amount": 3}]  这样的格式传 produceName为商品name ，amount 数量
            let proMarks = `<button onclick="addProductDelivery(this,'button');return false;" class='customization-button' style='width: 80px;
            font-size: 14px;
            height: 30px;display:none'>添加</button>`
            produceList.forEach(item => {
                proMarks += `
            <div style='display:flex;margin:5px 0px;' class="proMark-box">
            <textarea data-id='data' style='width:120px;' placeholder='请输入产品名称'>${item.produceName}</textarea>
            <div style='display: flex;
            flex-direction: column;justify-content: center;padding:0 5px'><div><span>数量:</span><input type='number' value='${item.amount}' placeholder='请输入数量' style="width:30px" min="1" onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}"/></div></div>
            <div style='display: flex;
            flex-direction: column;'><i class="layui-icon" style='color:#ff4444;font-size:20px;cursor: pointer;' onclick='delDp(this)'>&#xe640;</i><i class="layui-icon" style='color:#ff4444;font-size:20px;cursor: pointer;' onclick='addProductDelivery(this)'>&#xe61f;</i>
            </div>
            </div>
            `
            })
            module += `<td class="proMarks">${proMarks}</td>`
        } else {
            module += `<td class="proMarks"><button onclick="addProductDelivery(this,'button');return false;" class='customization-button' style='width: 80px;
        font-size: 14px;
        height: 30px;'>添加</button></td>
            `
        }
        module += `
    <td><span onclick="deleteRule(this)">删除</span></td>
    </tr>
    `
        rule.push(module);
    }
    $(".tableBorder_content").append(rule.join(""));
    if (
        !(
            tempname == undefined ||
            tempname == null ||
            tempname == "" ||
            tempname == "undefined" ||
            tempname == 0
        )
    ) {
        $("input").attr("readonly", true);

        $("textarea").attr("readonly", true);

        $(":radio").attr("disabled", true);
        $(":checkbox").attr("disabled", true);
        $(":button").attr("disabled", true);
        $("a").removeAttr("onclick");
        $("select").attr("disabled", true);
        $(".returns").remove("readonly");
    }
}

function deleteRule(e) {
    $(e).parents("tr").remove();
}

function updateOldPrice(obj) {
    var mealprice = parseFloat($(obj).parent().find(".mealprice").val()).toFixed(
        2
    );
    var discount =
        discount == 0 || discount == ""
            ? 0
            : parseFloat($(obj).parent().find(".discount").val()).toFixed(2);
    let tempInfo = ((mealprice / discount) * 10).toFixed(2);
    $(obj).parent().find(".mealoldprice").val(tempInfo);
}

//处理轮播图片
function select_img_list(imgList) {
    let infos = "";
    if (imgList.length > 0) {
        let imgArr = imgList.split(";");
        for (let i = 0; i < imgArr.length; i++) {
            let more_info = "";
            if (i == 0) {
                more_info = '<div class="form-label">商品轮播图片：</div>';
            }
            infos +=
                '<div class="form-group-col-2 lunt goods_list">' +
                more_info +
                '<div class="form-cont">' +
                '<input type="file" name="file"   onchange="upload_img(this,\'productImg\');" style="display: none;" />' +
                '<input class="btn btn-warning" value="请上传图片"  onclick="addclick(this)" type="button"/>' +
                '<span class="word-aux">请上传的图片宽高比例为1:1</span>' +
                "</div>" +
                "</div>" +
                '<div class="form-group-col-2 luntu divpreview"  id="divpreview">' +
                '<div class="form-label"></div>' +
                '<div class="form-cont">' +
                '<img id="preview" class="preview" name="' +
                imgArr[i] +
                '" src="' +
                visitimgurl +
                "/" +
                imgArr[i] +
                '" height="100" />' +
                '<p id="demoText" class="demoText"></p>' +
                "</div>" +
                "</div>";
        }
    } else {
        infos =
            '<div class="img_list">' +
            '<div class="form-group-col-2 lunt goods_list">' +
            '<div class="form-label">商品轮播图片：</div>' +
            '<div class="form-cont">' +
            '<input type="file" name="file"  onchange="upload_img(this,\'productImg\');"  style="display: none;" />' +
            '<input class="btn btn-warning" value="请上传图片"  onclick="addclick(this)" type="button"/>' +
            '<span class="word-aux">请上传的图片宽高比例为1:1</span>' +
            "</div>" +
            "</div>" +
            '<div class="form-group-col-2 divpreview luntu"  id="divpreview" style="display:none">' +
            '<div class="form-label"></div>' +
            '<div class="form-cont">' +
            '<img id="preview" class="preview" src="#" height="100" />' +
            '<p id="demoText" class="demoText"></p>' +
            "</div>" +
            "</div>" +
            "</div>";
    }
    $(".img_list").html(infos);
    if (
        !(
            tempname == undefined ||
            tempname == null ||
            tempname == "" ||
            tempname == "undefined" ||
            tempname == 0
        )
    ) {
        $("input").attr("readonly", true);

        $("textarea").attr("readonly", true);

        $(":radio").attr("disabled", true);
        $(":checkbox").attr("disabled", true);
        $(":button").attr("disabled", true);
        $("a").removeAttr("onclick");
        $("select").attr("disabled", true);
        $(".returns").remove("readonly");
    }
}

//提交商品
function submit_product_info() {
    let types = $("#types option:selected").val();
    if (types <= 0) {
        top.layer.alert("请选择商品类型!");
        return;
    }
    let bname = $("#bname").val();
    var identify = $("#identify").val();
    if (identify == "") {
        top.layer.alert("请输入商品编号!");
        return;
    }
    let pro_name = $("#pro_name").val();
    if (pro_name == "") {
        top.layer.alert("请输入商品名称!");
        return;
    }
    //是否上架
    let isshelves = $("input[name='isshelves']:checked").val();
    //是否赠品
    let give = $("input[name='give']:checked").val();
    //是否包邮
    let isfree = $("input[name='isfree']:checked").val();
    //人气好茶
    let isnew = $("input[name='isnew']:checked").val();
    //送礼首选
    let isrecomm = $("input[name='isrecomm']:checked").val();
    //推荐商品(购物车)
    let isrecommtu = $("input[name='isrecommtu']:checked").val();
    //推荐商品(首页)
    let homeRecommend = $("input[name='homeRecommend']:checked").val();
    //收藏佳品
    let iscrux = $("input[name='iscrux']:checked").val();
    
    //会员折扣商品
    let discount = $("input[name='discount']:checked").val();
    let exchanges = $("input[name='exchanges']:checked").val();

    let sort = $("#sort").val();
    if (sort == "") {
        top.layer.alert("请输入商品排序！");
        return;
    }
    //商品主图
    let divpreview_img = $("#preview").attr("name");
    if (divpreview_img == "") {
        top.layer.alert("请添加商品首页图片！");
        return;
    }

    //商品轮播图片
    let goods_img_list = "";
    $(".goods_list").each(function () {
        goods_img_list += $(this).next().find(".preview").attr("name") + ";";
    });
    if (goods_img_list == "") {
        top.layer.alert("请添加商品轮播图片!");
        return;
    }
    goods_img_list = goods_img_list.substring(0, goods_img_list.length - 1);

    if ($(".rules").length == 0) {
        top.layer.alert("请至少添加一个套餐!");
        return;
    }
    //套餐
    let tempinfo = "";
    let setmealInfo = "";

    $(".rules").each(function () {
        let productList = []
        let mealObj = ''
        let id = $(this).attr("id") || 0;
        let mealname = $(this).find(".mealname").val();
        let discount = $(this).find(".discount").val();
        let mealoldprice = $(this).find(".mealoldprice").val();
        let mealprice = $(this).find(".mealprice").val();
        let mealstock = $(this).find(".mealstock").val();
        let freight = $(this).find(".freight").val() || 0;
        let newspecials = $(this).find(".newspecials").val();
        $(this).find(".proMarks>div").each(function () {
            let proObj = {}
            proObj.produceName = $(this).find('textarea').text();
            proObj.amount = $(this).find('input').val();
            if (proObj.produceName) {
                productList.push(proObj)
            } else {
                productList = []
            }
        })
        // console.log(JSON.stringify(productList));
        if (discount == "" || discount == 0) {
            mealoldprice = mealprice;
            discount = 0;
        }
        if (mealname == "") {
            tempinfo = "存在未填写的套餐规格";
        }
        if (
            (isNotNull(discount) && mealoldprice == "") ||
            (discount != 0 && mealoldprice == "")
        ) {
            tempinfo = "存在未填写的套餐市场价";
        }
        if (mealprice == "") {
            tempinfo = "存在未填写的套餐现价";
        }

        if (freight == "") {
            tempinfo = "存在未填写的套餐运费";
        }
        if (newspecials == "") {
            tempinfo = "存在未填写的新人价格";
        }
        if (mealstock == "") {
            tempinfo = "存在未填写的库存";
        }
        if (productList.length > 0) {
            mealObj = `{"id":${id},"mealname":"${mealname}","mealoldprice":${mealoldprice},"mealprice":${mealprice},"mealstock":${mealstock},"discount":"${discount}","freight":${freight},"newspecials":${newspecials},"produceList":${JSON.stringify(productList)}},`;

        } else {
            mealObj = `{"id":${id},"mealname":"${mealname}","mealoldprice":${mealoldprice},"mealprice":${mealprice},"mealstock":${mealstock},"discount":"${discount}","freight":${freight},"newspecials":${newspecials}},`;

        }
        setmealInfo += mealObj;
    });

    if (tempinfo != "") {
        top.layer.alert(tempinfo);
        return;
    }
    setmealInfo = setmealInfo.substring(0, setmealInfo.length - 1);
    setmealInfo = `[${setmealInfo}]`;
    if (setmealInfo.length <= 0) {
        top.layer.alert("请至少填写一个套餐类型!");
        return;
    }
    //简介
    let pro_content = UE.getEditor("container").getContent();
    if (pro_content == "") {
        top.layer.alert("请输入商品简介!");
        return;
    }
    // 添加发货商品列表

    top.layer.confirm(
        "确认提交？",
        { icon: 3, title: "提示信息" },
        function (index) {
            var index = top.layer.msg("提交中，请稍候", {
                icon: 16,
                time: false,
                shade: 0.8,
            });
            let httpAjax = "UpdateProductById";
            if (productid == 0) {
                httpAjax = "InsertProduct";
            }
            $.ajax({
                type: "POST",
                url: httpurl + "/" + httpAjax,
                cache: false,
                headers: {
                    "Access-Control-Allow-Origin": "*",
                    "Access-Control-Allow-Methods": "*",
                    "Access-Control-Allow-Headers": "Authorization",
                    Authorization: GetTokenInfo(),
                },
                contentType: "application/json",
                data: JSON.stringify({
                    id: productid,
                    tid: types,
                    title: pro_name,
                    sort: sort,
                    isshelves: isshelves,
                    headimg: divpreview_img,
                    img: goods_img_list,
                    details: pro_content,
                    setmealInfo: setmealInfo,
                    give: give,
                    isfree: isfree,
                    isnew: isnew,
                    iscrux: iscrux,
                    isrecomm: isrecomm,
                    isrecommtu: isrecommtu,
                    bname: bname,
                    exchanges: exchanges,
                    identify: identify,
                }),
                success: function (data) {
                    layer.closeAll();

                    if (data.rtnCode == 200) {
                        window.location.href = "ProductList.html?pageNo=" + pageNo;
                        return;
                    }
                    top.layer.msg(data.msg);
                },
                error: (err) => {
                    layer.closeAll();
                    top.layer.alert("修改未成功");
                },
            });
        },
        function () { }
    );
}

function re() {
    if (
        !(
            tempname == undefined ||
            tempname == null ||
            tempname == "" ||
            tempname == "undefined" ||
            tempname == 0
        )
    ) {
        window.location.href = "ProductListQuery.html?pageNo=" + pageNo;
    } else {
        window.location.href = "ProductList.html?pageNo=" + pageNo;
    }
}
